<?php
// ----------------------------------------------------------------------
// Source file:  $Source: /cvsroot/pn-commerce/pn-commerce/search_defines.php,v $
//
// Last changes from:  $Author: landseer $
//
// Revision:           $Revision: 1.2 $
//
// Date of revision    $Date: 2003/02/27 11:09:19 $
//  
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Ask for a file, open it and display all _STRINGS in it.

// first version, we get the filename as argument

$_GET['file'];
$valid = "_ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567980";
$valid2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";

$lines = array();
$found = array();

if ( file_exists ($file) )
{
	$lines = file ($file);
	echo count($lines)." lines read from $file<br><br>";
	foreach ($lines as $line)
	// now the real work starts...
	{
		$line = strip_tags ($line);
		if ( substr_count ($line, "_") > 0 )
		{
			while ( substr_count ($line, "_") > 0 )
			{
				// forget everything left from the _
				$line = strchr ($line, "_");
				// if the next char is uppercase, it is a define
				// _ is now at pos. 0 so we check pos. 1
				$c2 = substr ($line, 1, 1);
				if ( substr_count ($valid2, $c2) > 0 )
				{
					// now find the next char that is not ABC...XYZ uppercase !!
					// this marks the end of the define
					// then copy everything from the start till this char to $define
					$define = substr ($line, 0 ,strspn ($line, $valid));
					// now replace the define found in $line with nothing -> remove it from $line
					$line = ereg_replace ($line, $define, "");
					// add the found define to the array
					$found[] = $define;
				}
				else
				{
					// 2nd char is not valid, kill the _ and continue search
					$line = ereg_replace ("_", "", $line);
				}
			}
		}
	}
	$total = count($found);
	$found = array_unique ($found);
	asort ($found);	
	echo count($found)." unique defines from a total of $total found:<br><br>";
	foreach ($found as $out)
	{
		echo $out."<br>";
	}
}
else
{
	echo "unknown file $file";
}

?>